package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @author vivi
 * @description
 * @date 2024/5/30
 */
@RestController
@RequestMapping ("/user")
public class UserController {

//    @GetMapping
//    public String getStr() {
//        return "执行 GET 请求方式！";
//    }
//
//    @PostMapping
//    public String postMethod() {
//        return "执行 POST 请求方式！";
//    }

    @RequestMapping("/getnum")
    public Integer getNum() {
        return new Random().nextInt(10);
    }

    @RequestMapping ("/getuser")
    public String getUser() {
        System.out.println("执行了 getUser 方法！");
        return "getUser";
    }
    @RequestMapping ("/login")
    public String login() {
        Object obj = null;
        obj.hashCode(); // 自创异常
        System.out.println("执行了 login 方法！");
        return "login";
    }
    @RequestMapping ("/reg")
    public String reg() {
        int num = 10/0; // 自创异常
        System.out.println("执行了 reg 方法！");
        return "reg";
    }
}


























